package com.grt192.benchtest.controller;

import com.grt192.benchtest.mechanism.BenchRollers;
import com.grt192.core.EventController;
import com.grt192.event.SensorEvent;
import com.grt192.event.component.ButtonListener;
import com.grt192.event.component.JoystickEvent;
import com.grt192.event.component.JoystickListener;
import com.grt192.mechanism.GRTDriverStation;
import com.grt192.sensor.GRTJoystick;

/**
 *
 * @author anand
 */
public class BenchRollerController extends EventController implements ButtonListener, JoystickListener {

    private BenchRollers rollers;
    private GRTDriverStation ds;

    public BenchRollerController(BenchRollers rollers, GRTDriverStation ds) {
        this.rollers = rollers;
        this.ds = ds;
        ((GRTJoystick) ds.getSensor("leftJoystick")).addButtonListener(this);
        ((GRTJoystick) ds.getSensor("leftJoystick")).addJoystickListener(this);

    }

    public void buttonUp(SensorEvent e, String key) {
        if (key.equals("Button3") || key.equals("Button4")) {
            rollers.stop();
        }
    }

    public void buttonDown(SensorEvent e, String key) {
        if (key.equals("Button3")) {
            rollers.spinForward();
        } else if (key.equals("Button4")) {
            rollers.spinBackward();
        }
    }

    public void xAxisMoved(JoystickEvent e) {
    }

    public void yAxisMoved(JoystickEvent e) {
    }

    public void zAxisMoved(JoystickEvent e) {
        rollers.setSpeed((1.0 + e.getValue()) / 2.0);
        if(rollers.isSpinning())
            rollers.spinForward();
    }

    public void throttleMoved(JoystickEvent e) {
    }
}
